﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MyBBS.Services;

namespace MyBBS.Controllers
{
    public class BaseController : Controller
    {

        protected IUserService _userService;

        public BaseController(IUserService userService)
        {
            _userService = userService;
        }

        public bool IsAuthenticated
        {
            get
            {
                return HttpContext.User.Identity.IsAuthenticated;
            }
        }

        public string UserName
        {
            get
            {
                return IsAuthenticated ? HttpContext.User.Identity.Name : "Anonymous";
            }
        }

        public Guid CurrentUserID
        {
            get
            {
                if (IsAuthenticated)
                    return _userService.GetUserByUserName(UserName).ID;
                else
                    return Guid.Empty;
            }
        }
    }
}
